﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    @Styles.Render("~/bundles/css")
    <style>
        .ul {
            display: flex;
        }

            .ul li {
                list-style: none;
                flex: 1;
                min-width: 10%;
                height: 100px;
                text-align: center;
                line-height: 100px;
                background: #0094ff;
                border-radius: 10px;
                color: #fff;
                margin-left: 10px;
                cursor: pointer;
            }
    </style>
</head>
<body>
    <blockquote class="layui-elem-quote layui-text">
        代码生成之前请先编译已创建好的实体类
    </blockquote>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>请选择实体类</legend>
    </fieldset>
    <form class="layui-form ">
        <div class="layui-form-item">
            <label class="layui-form-label">实体类</label>
            <div class="layui-input-block">
                @{ foreach (KeyValuePair<string, string> item in ViewBag.list)
                    {
                        <input type="checkbox" name="@(item.Key+"|"+item.Value)" title="@(item.Key+"("+item.Value+")")">
                    }

                }


            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">自动包含</label>
            <div class="layui-input-block">
                <input type="checkbox" name="autoContain" lay-skin="switch" lay-text="ON|OFF">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">自动编译</label>
            <div class="layui-input-block">
                <input type="checkbox" name="autoCompliez" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="btnGenCode" lay-submit="" lay-filter="formData">生成代码</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <div>

    </div>
    <script src="~/js/jquery-1.10.2.min.js"></script>
    
    <script type="text/javascript" src="~/layui/layui.js"></script>
    <script>
        layui.use(['form','jquery'], function () {
            var form = layui.form;
            var $ = layui.$;


            form.on('submit(formData)', function (data) {
                var tables = "";
                for (var i in data.field) {

                    tables += i + ';';

                }
                if (!tables) {
                    layer.alert('请选择实体类！');
                    return false;
                }
                $.getJSON('@Url.Action("genCode")' + "?tableNames=" + tables, function (res) {
                    if (res.success) {
                        layer.msg("生成代码成功！");
                    } else {
                        layer.alert("生成失败，请检查是否已经生成代码！");
                    }

                })
                return false;
            });

            //$('#btnGenCode').on('click', function () {



                @*var index = layer.msg(
                    "正在生成文件...",
                    {
                        shade: [0.8, '#393D49'],
                        time: 100000,
                });



                var timer = setInterval(function () {

                    $.ajax({
                        url: '@Url.Action("complie")',
                        timeout:4000,
                        success: function (res) {
                            if (res.indexOf("{") == 0) {
                                layer.close(index);
                                layer.alert('编译成功！');
                                clearInterval(timer);
                            }

                        }
                    })


                },5000)*@

            //    return false;
            //})


        })
    </script>
</body>


</html>
